package com.itheima.hashset1;

import java.util.HashSet;
import java.util.Set;

public class Test {

    public static void main(String[] args) {

        //HashSet的去重
        //如果希望Set集合认为两个内容一样的对象是重复的，则必须重写对象的hashCode()和equals()方法

        Student s1 = new Student("张三", 20, 3, "北京");
        Student s2 = new Student("张三", 20, 3, "北京");
        Student s3 = new Student("李四", 23, 4, "深圳");
        Student s4 = new Student("王五", 32, 5, "上海");
        Student s5 = new Student("王五", 32, 5, "上海");
        Student s6 = new Student("赵六", 28, 6, "香港");

        //6个不同对象的哈希值不同，所以HashSet没有去重
        Set<Student> set = new HashSet<Student>();
        set.add(s1);
        set.add(s2);
        set.add(s3);
        set.add(s4);
        set.add(s5);
        set.add(s6);
        System.out.println(set);
    }
}
